﻿using UnityEngine;
using System.Collections.Generic;
using ProtoBuf.Message;
using UI;

namespace Room
{
    public class NetUnionFightBaseCamp : NetUnionFightBase
    {
       
        public Dictionary<long, InstUFBaseCamp> baseCamps = new Dictionary<long, InstUFBaseCamp>();

        public NetUnionFightBaseCamp(RoomUnionFight unionFight, RoomCharactorManager mgr, RoomNetUnionFight net)
            :base(unionFight,mgr,net)
        {
        }

        public override void Enter()
        {
            base.Enter();
            baseCamps.Clear();
        }

        public override void Leave()
        {
            base.Leave();
            baseCamps.Clear();
        }

        public override RoomCharactor CreateCharactor(long uuid)
        {
            var camp = baseCamps[uuid];
            charactorManager.CreateUnionBaseCamp(camp);
            baseCamps[uuid] = camp;
            return GetCharactor(uuid+"");
        }

        public override void ClearCharactorData(long uuid)
        {
            base.ClearCharactorData(uuid);

            if (baseCamps.ContainsKey(uuid))
                baseCamps.Remove(uuid);
        }

        /// <summary>
        /// 基地刷新
        /// </summary>
        /// <param name="msg"></param>
        public void BaseCampRefresh(SCUFBaseCamp msg)
        {
            if (msg != null)
            {
                foreach (var camp in msg.baseCamp)
                {
                    BaseCampRefresh(camp);
                }
            }
        }

        /// <summary>
        /// 基地刷新
        /// </summary>
        /// <param name="msg"></param>
        public void BaseCampRefresh(InstUFBaseCamp bc)
        {
            if (bc != null)
            {
                var uuid = bc.guid;
                baseCamps[uuid] = bc;

                var camp = GetCharactor(uuid,false);

                if (camp == null)
                {
                    camp = CreateCharactor(uuid);
                }

                var postion = Dict.Blo.DictUnionFightBaseCampBlo.GetPosition(bc.id + "");
                UpdatePosition(uuid, postion);
#if UNITY_EDITOR
                camp.Camp = bc.camp;
#endif

                //刷基地守卫
                net.netGuard.GuardRefresh(bc.guard);

#if UNITY_EDITOR
                var guard = GetCharactor( bc.guard.bindGuid);
                guard.Camp = bc.camp;
#endif

            }
        }
    }


}